package com.gobang.common.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * 游戏核心模块配置类
 * 配置游戏核心功能所需的Bean
 * 
 * @author System
 * @since 1.0.0
 */
@Configuration
public class GameCoreConfig {

    /**
     * 配置游戏专用ObjectMapper
     *
     * @return ObjectMapper实例
     */
    @Bean
    public ObjectMapper gameObjectMapper() {
        ObjectMapper mapper = new ObjectMapper();
        
        // 注册Java时间模块:解决无法正确处理 JAVA 8的时间类型
        mapper.registerModule(new JavaTimeModule());
        
        // 使用蛇形命名策略
        // userName-》user_name
        // mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
        
        // 忽略未知属性
        // 默认，如果 JSON 包含 JAVA 对象没有的字段，会抛异常
        mapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        
        return mapper;
    }
} 